package org.ssp.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.ssp.base.ResultSetHanlder;
import org.ssp.dao.ApplyStepDao;
import org.ssp.pojo.ApplyStep;
import org.ssp.util.DBUtil;

public class ApplyStepImpl implements ApplyStepDao{

	@Override
	public void add(ApplyStep applystep) {
		String sql="insert into applystep(id,content,dattime) values(1,?,curdate()) ";
		DBUtil.update(sql, applystep.getContent());
	}

	@Override
	public ApplyStep find() {
		String sql="select * from applystep where id=1;";
		return (ApplyStep)DBUtil.query(sql, new ResultSetHanlder() {
			
			@Override
			public Object doHandler(ResultSet rs) {
				ApplyStep app=null;
				try {
					if(rs.next()){
						app=new ApplyStep();
						app.setId(rs.getInt("id"));
						app.setContent(rs.getString("content"));
						app.setDate(rs.getDate("dattime"));
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
				return app;
			}
		}, null);
	}

	@Override
	public void update(ApplyStep applystep) {
		String sql="update applystep set content=? where id=1;";
		DBUtil.update(sql, applystep.getContent());
	}
	@Override
	public void delete() {
		String sql="delete from applystep where id=1;";
		DBUtil.update(sql, null);
	}

}
